﻿<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>Suucha Expression Js 单元测试</title>
    <script src="http://code.jquery.com/jquery-latest.js" type="text/javascript"></script>
    <link rel="stylesheet" href="qunit.css" type="text/css" media="screen" />
    <script type="text/javascript" src="qunit.js"></script>
    <script src="json2.js" type="text/javascript"></script>
    <script type="text/javascript" src="Suucha.Expression.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            test("From json", function () {
                var json = eval('({"Left":{"Left":{"Value":1,"NodeType":1},"Right":{"Value":1,"NodeType":1},"NodeType":3},"Right":{"Left":{"Name":"Code","NodeType":0},"Right":{"Value":"1.1","NodeType":1},"NodeType":3},"NodeType":2})');
                var exp = Suucha.Expression.FromJson(json);
                QUnit.equal(1, exp.Left.Left.Value, "我们期望得到1");
            });
            test('Order by', function () {
                var orderBy = new Suucha.OrderBy({ Member: Suucha.Expression.Member('Name'), Asc: true }).ThenBy('Code'); //Suucha.OrderBy.OrderBy("Name").ThenByDescending("Code");
                QUnit.equal(2, orderBy.ToArray().length);

            });
            test('Search prameters', function () {
                var search = new Suucha.SearchParameters();
                search.Sorts = new Suucha.OrderBy({ Member: Suucha.Expression.Member('Name'), Asc: true }).ThenBy('Code').ToArray();
                search.Condition = Suucha.Expression.Equal('Name', 'name1');
                var json = JSON.stringify(search);
                var se = Suucha.SearchParameters.FromJson(eval('(' + json + ')'));

                QUnit.equal(2, se.Sorts.length);
                QUnit.equal('Name', se.Condition.Left.Name);
                QUnit.equal('name1', se.Condition.Right.Value);
            });
        });
    </script>
</head>
<body>
    <h1 id="qunit-header">
        Suucha Expression Js 单元测试</h1>
    <h2 id="qunit-banner">
    </h2>
    <h2 id="qunit-userAgent">
    </h2>
    <ol id="qunit-tests">
    </ol>
</body>
</html>
